#!/bin/bash

NUM=$(ifconfig | grep -A1 "eth0" | grep -Eo "inet addr:([1-9.]*)" | grep -Eo [^.]*$ )
echo "NUM is ${NUM}"

URL="http://oscg-downloads.s3.amazonaws.com/packages/postgres-9.0.3-1.amd64.openscg.deb"
echo "Downloading..."
wget ${URL}
echo "Installing..."
dpkg -i postgres-9.0.3-1.amd64.openscg.deb
echo "Config..."
cp ./postgres-9.0-openscg /etc/init.d/
sed -i "s/BREAD_DB=.*$/BREAD_DB=\/mnt\/db${NUM}/g" /etc/init.d/postgres-9.0-openscg 
echo "Start the service..."
/etc/init.d/postgres-9.0-openscg restart
echo "Copy password..."
cp ./.pgpass ~/
chmod 0600 ~/.pgpass
